//
//  UserModel.m
//  BuyWhat
//
//  Created by ios on 2016/11/1.
//  Copyright © 2016年 吕金状. All rights reserved.
//

#import "UserModel.h"
static NSString * const KEY_USERID = @"KEY_USERID";
static NSString * const KEY_NICKNAME = @"KEY_NICKNAME";
static NSString * const KEY_USERPocketID = @"KEY_USERPocketID";
static NSString * const KEY_IMGURL = @"KEY_IMGURL";
static NSString * const KEY_SHOWGUIDEFIGURE = @"KEY_SHOWGUIDEFIGURE";
static NSString * const KEY_TOKEN = @"KEY_TOKEN";
static NSString * const KEY_APP_THIRD_URL = @"KEY_APP_THIRD_URL";
static NSString * const KEY_MONEY = @"KEY_MONEY";
static NSString * const KEY_WELCOME = @"KEY_WELCOME";
static NSString * const KEY_JPUSGH = @"KEY_JPUSGH";
static NSString * const KEY_FMEMO = @"KEY_FMEMO";
static NSString * const KEY_FID = @"KEY_FID";
static NSString * const KEY_TEXT = @"TEXTSTR";
static NSString * const KEY_PERSON = @"KEY_PERSON";
static NSString * const KEY_MEMDIS = @"KEY_MEMDIS";
static NSString * const KEY_CONTACT = @"KEY_CONTACT";
static NSString * const KEY_ADRESS = @"KEY_ADRESS";
static NSString * const KEY_SHOP = @"KEY_SHOP";
static NSString * const KEY_STORE = @"KEY_STORE";
static NSString * const KEY_ORDERNO = @"KEY_ORDERNO";
static NSString * const KEY_CASH = @"KEY_CASH";

static NSString * const KEY_FMEMO1 = @"KEY_FMEMO1";
static NSString * const KEY_FID1 = @"KEY_FID1";
static NSString * const KEY_PASSWORD = @"KEY_PASSWORD";


@interface UserModel();

@end

@implementation UserModel

+(UserModel*)sharedInstanced{
    static UserModel *_userLogon = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _userLogon = [[UserModel alloc] init];
    });
    return _userLogon;
}

- (id)init{
    self = [super init];
    if (!self) {
        return nil;
    }
    return self;
}



#pragma mark - userID
//山海慧用户名
- (NSString *)userID {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_USERID:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_USERID];
}

- (void)setUserID:(NSString *)userID {
    if (!userID) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_USERID];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_USERID];
    //判断是否需要更新
    if ([currentUserID isEqualToString:userID]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:userID forKey:KEY_USERID];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - password
//山海慧密码
- (NSString *)password {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_PASSWORD:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_PASSWORD];
}

- (void)setPassword:(NSString *)password {
    if (!password) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_PASSWORD];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_PASSWORD];
    //判断是否需要更新
    if ([currentUserID isEqualToString:password]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:KEY_PASSWORD];
    [[NSUserDefaults standardUserDefaults] synchronize];
}






#pragma mark - fMemo
//山海慧门店
- (NSString *)fMemo {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_FMEMO:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_FMEMO];
}

- (void)setFMemo:(NSString *)fMemo {
    if (!fMemo) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_FMEMO];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_FMEMO];
    //判断是否需要更新
    if ([currentUserID isEqualToString:fMemo]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:fMemo forKey:KEY_FMEMO];
    [[NSUserDefaults standardUserDefaults] synchronize];
}



#pragma mark - userID
//山海慧药房Id
- (NSString *)fid {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_FID:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_FID];
}

- (void)setFid:(NSString *)fid {
    if (!fid) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_FID];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_FID];
    //判断是否需要更新
    if ([currentUserID isEqualToString:fid]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:fid forKey:KEY_FID];
    [[NSUserDefaults standardUserDefaults] synchronize];
}






- (void)setTextStr:(NSString *)textStr {
    if (!textStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_TEXT];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_TEXT];
    //判断是否需要更新
    if ([currentUserID isEqualToString:textStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:textStr forKey:KEY_TEXT];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - personTestStr
//山海慧收货人
- (NSString *)personTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_PERSON:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_PERSON];
}

- (void)setPersonTestStr:(NSString *)personTestStr {
    if (!personTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_PERSON];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_PERSON];
    //判断是否需要更新
    if ([currentUserID isEqualToString:personTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:personTestStr forKey:KEY_PERSON];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - contactTestStr
//山海慧收货方式
- (NSString *)contactTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_CONTACT:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_CONTACT];
}

- (void)setContactTestStr:(NSString *)contactTestStr {
    if (!contactTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_CONTACT];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_CONTACT];
    //判断是否需要更新
    if ([currentUserID isEqualToString:contactTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:contactTestStr forKey:KEY_CONTACT];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - adressTestStr
//山海慧配送地址
- (NSString *)adressTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_ADRESS:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_ADRESS];
}

- (void)setAdressTestStr:(NSString *)adressTestStr {
    if (!adressTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_ADRESS];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_ADRESS];
    //判断是否需要更新
    if ([currentUserID isEqualToString:adressTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:adressTestStr forKey:KEY_ADRESS];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - memDisTestStr
//山海慧会员配送备注
- (NSString *)memDisTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_MEMDIS:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_MEMDIS];
}

- (void)setMemDisTestStr:(NSString *)memDisTestStr {
    if (!memDisTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_MEMDIS];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_MEMDIS];
    //判断是否需要更新
    if ([currentUserID isEqualToString:memDisTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:memDisTestStr forKey:KEY_MEMDIS];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - shopTestStr
//山海慧门店配送备注
- (NSString *)shopTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_SHOP:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_SHOP];
}

- (void)setShopTestStr:(NSString *)shopTestStr {
    if (!shopTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_SHOP];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_SHOP];
    //判断是否需要更新
    if ([currentUserID isEqualToString:shopTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:shopTestStr forKey:KEY_SHOP];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - storeTestStr
//山海慧门店自提备注
- (NSString *)storeTestStr {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_STORE:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_STORE];
}

- (void)setStoreTestStr:(NSString *)storeTestStr {
    if (!storeTestStr) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_STORE];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_STORE];
    //判断是否需要更新
    if ([currentUserID isEqualToString:storeTestStr]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:storeTestStr forKey:KEY_STORE];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


#pragma mark - orderNo
//山海慧门店自提备注
- (NSString *)orderNo {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_ORDERNO:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_ORDERNO];
}

- (void)setOrderNo:(NSString *)orderNo {
    if (!orderNo) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_ORDERNO];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_ORDERNO];
    //判断是否需要更新
    if ([currentUserID isEqualToString:orderNo]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:orderNo forKey:KEY_ORDERNO];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - inputCashText
//山海慧门店自提备注
- (NSString *)inputCashText {
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_CASH:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_CASH];
}

- (void)setInputCashText:(NSString *)inputCashText {
    if (!inputCashText) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_CASH];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_CASH];
    //判断是否需要更新
    if ([currentUserID isEqualToString:inputCashText]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:inputCashText forKey:KEY_CASH];
    [[NSUserDefaults standardUserDefaults] synchronize];
}













#pragma mark - nickName

- (NSString *)nickName{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_NICKNAME:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_NICKNAME];
}

/**
 设置用户名
 
 @param nickName 用户名
 */
- (void)setNickName:(NSString *)nickName{
    if (!nickName) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_NICKNAME];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentNickName = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_NICKNAME];
    //判断是否需要更新
    if ([currentNickName isEqualToString:nickName]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:nickName forKey:KEY_NICKNAME];
    [[NSUserDefaults standardUserDefaults] synchronize];

}


#pragma mark - imgUrl

- (NSString *)imgUrl{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_IMGURL:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_IMGURL];
}

/**
 设置背景图片
 
 @param imgUrl 背景图片
 */
- (void)setImgUrl:(NSString *)imgUrl{
    if (!imgUrl) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_IMGURL];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_IMGURL];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:imgUrl]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:imgUrl forKey:KEY_IMGURL];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

#pragma mark - token

- (NSString *)token{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_TOKEN:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_TOKEN];
}

/**
 token
 
 @param token token description
 */
- (void)setToken:(NSString *)token{
    if (!token) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_TOKEN];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_TOKEN];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:token]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:KEY_TOKEN];
    [[NSUserDefaults standardUserDefaults] synchronize];

    
}
#pragma mark - app_third_url

- (NSString *)app_third_url{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_APP_THIRD_URL:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_APP_THIRD_URL];
}

/**
 web页地址
 
 @param app_third_url app_third_url description
 */
- (void)setApp_third_url:(NSString *)app_third_url{
    if (!app_third_url) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_APP_THIRD_URL];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_APP_THIRD_URL];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:app_third_url]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:app_third_url forKey:KEY_APP_THIRD_URL];
    [[NSUserDefaults standardUserDefaults] synchronize];

    
}
#pragma mark - money

- (NSString *)money{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_MONEY:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_MONEY];
}

/**
 金额
 
 @param money money description
 */
- (void)setMoney:(NSString *)money{
    if (!money) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_MONEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_MONEY];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:money]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:money forKey:KEY_MONEY];
    [[NSUserDefaults standardUserDefaults] synchronize];

    
}

#pragma mark - welcome

- (NSString *)welcome{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_WELCOME:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_WELCOME];
}

/**
 欢迎语
 
 @param welcome money description
 */
- (void)setWelcome:(NSString *)welcome{
    if (!welcome) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_WELCOME];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_WELCOME];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:welcome]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:welcome forKey:KEY_WELCOME];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    
}

#pragma mark - jpush_key

- (NSString *)jpush_key{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_JPUSGH:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_JPUSGH];
}

- (void)setJpush_key:(NSString *)jpush_key{
    if (!jpush_key) {
        [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:KEY_JPUSGH];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return;
    }
    //获取本地数据
    NSString *currentImgUrl = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_JPUSGH];
    //判断是否需要更新
    if ([currentImgUrl isEqualToString:jpush_key]) {
        return;
    }
    
    [[NSUserDefaults standardUserDefaults] setObject:jpush_key forKey:KEY_JPUSGH];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark - 是否显示引导图

- (NSString *)showGuideFigure{
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{KEY_SHOWGUIDEFIGURE:@""}];
    return [[NSUserDefaults standardUserDefaults] objectForKey:KEY_SHOWGUIDEFIGURE];
}


- (void)setShowGuideFigure:(NSString *)showGuideFigure{
    if (!showGuideFigure) {
        return;
    }
    //获取本地数据
    NSString *currentUserID = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_SHOWGUIDEFIGURE];
    //判断是否需要更新
    if ([currentUserID isEqualToString:showGuideFigure]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setObject:showGuideFigure forKey:KEY_SHOWGUIDEFIGURE];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

@end
